package primalgorithms.string;

public class _09LongestCommonPrefix {
    public static String longestCommonPrefix(String[] strs) {
        if(strs.length == 0){
            return "";
        }
        //这里采用逆向思维 ==> startsWith方法
        String res = strs[0];
        for (String str : strs){
            while (!str.startsWith(res)){
                /** 注意!
                 *  Condition 'res.length()==0' is always 'false'
                 *   if(res.length() == 0){
                 *       return "";
                 *   }
                */
                res = res.substring(0,res.length()-1);
            }
        }
        return res;
    }
}
